package ProyectoX;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Clase Explosion extiende Thread
 * */
public class Explosion extends Thread {
	protected JPanel panel;
	protected NaveEnemiga Enem;
	protected JLabel explosion;
	
	/**
	 * Constructor Explosion
	 * Inicializa los atributos.
	 * */
	public Explosion( NaveEnemiga Enem, JPanel panel ) {
		this.panel = panel;
		this.Enem = Enem;
	}
	
	/**
	 * Crea una label que luego de un sleep sera removida del panel 		
	 */
	public void run() {
		try {
			Thread.sleep(150);
			
			explosion = new JLabel();
			explosion.setIcon(new ImageIcon(getClass().getClassLoader().getResource("Imagenes/Explosion.gif")));
			Enem.MiNivel.juego.jPanelNivel.add(explosion);
			explosion.setBounds(Enem.getX()-Enem.getWidth(), Enem.getY()-Enem.getHeight(), explosion.getIcon().getIconWidth(), explosion.getIcon().getIconHeight());

			Thread.sleep(1000);

			this.panel.remove(explosion);
			panel.repaint();
		
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}
}